package com.ruoyi.mng.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.mng.domain.HzCard;
import com.ruoyi.mng.service.IHzCardService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 卡状态Controller
 * 
 * @author Qiang
 * @date 2023-04-23
 */
@Controller
@RequestMapping("/mng/card")
public class HzCardController extends BaseController
{
    private String prefix = "mng/card";

    @Autowired
    private IHzCardService hzCardService;

    @RequiresPermissions("mng:card:view")
    @GetMapping()
    public String card()
    {
        return prefix + "/card";
    }

    /**
     * 查询卡状态列表
     */
    @RequiresPermissions("mng:card:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(HzCard hzCard)
    {
        startPage();
        List<HzCard> list = hzCardService.selectHzCardList(hzCard);
        return getDataTable(list);
    }

    /**
     * 导出卡状态列表
     */
    @RequiresPermissions("mng:card:export")
    @Log(title = "卡状态", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(HzCard hzCard)
    {
        List<HzCard> list = hzCardService.selectHzCardList(hzCard);
        ExcelUtil<HzCard> util = new ExcelUtil<HzCard>(HzCard.class);
        return util.exportExcel(list, "卡状态数据");
    }

    /**
     * 新增卡状态
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存卡状态
     */
    @RequiresPermissions("mng:card:add")
    @Log(title = "卡状态", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(HzCard hzCard)
    {
        return toAjax(hzCardService.insertHzCard(hzCard));
    }

    /**
     * 修改卡状态
     */
    @RequiresPermissions("mng:card:edit")
    @GetMapping("/edit/{cardId}")
    public String edit(@PathVariable("cardId") Long cardId, ModelMap mmap)
    {
        HzCard hzCard = hzCardService.selectHzCardByCardId(cardId);
        mmap.put("hzCard", hzCard);
        return prefix + "/edit";
    }

    /**
     * 修改保存卡状态
     */
    @RequiresPermissions("mng:card:edit")
    @Log(title = "卡状态", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(HzCard hzCard)
    {
        return toAjax(hzCardService.updateHzCard(hzCard));
    }

    /**
     * 删除卡状态
     */
    @RequiresPermissions("mng:card:remove")
    @Log(title = "卡状态", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(hzCardService.deleteHzCardByCardIds(ids));
    }
}
